from django.db import models


class Role(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    role = models.CharField(db_column='role', max_length=10)

    def __str__(self):
        return '%s' % self.role

    class Meta:
        db_table = 'role'
        verbose_name_plural = '角色'


class Instructor(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    instructor = models.CharField(db_column='instructor', max_length=10)

    def __str__(self):
        return '%s' % self.instructor

    class Meta:
        db_table = 'instructor'
        verbose_name_plural = '辅导员'


class StudentClass(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    classname = models.CharField(db_column='classname', max_length=30)
    instructor_id = models.ForeignKey(Instructor, models.DO_NOTHING, db_column='instructor_id',
                                      related_name='instructor_name')  # 辅导员id

    def __str__(self):
        return '%s' % self.classname

    class Meta:
        db_table = 'student_class'
        verbose_name_plural = '班级'


class User(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    name = models.CharField(db_column='name', max_length=20, verbose_name='姓名')
    username = models.CharField(db_column='username', max_length=20, help_text='学号', verbose_name='学号')
    password = models.CharField(db_column='password', max_length=30, help_text='密码默认学号后六位', verbose_name='密码')

    def __str__(self):
        return '%s' % self.name

    class Meta:
        db_table = 'user'
        verbose_name_plural = '用户'


class UserInfo(models.Model):
    SEX_CHOICES = (
        ('0', '女生'),
        ('1', '男生')
    )
    id = models.AutoField(db_column='id', primary_key=True)
    user_id = models.ForeignKey(User, models.DO_NOTHING, db_column='user_id', related_name='userinfo')
    role_id = models.ForeignKey(Role, models.DO_NOTHING, db_column='role_id', verbose_name='角色')
    instructor_id = models.ForeignKey(Instructor, models.DO_NOTHING, db_column='instructor_id', verbose_name='辅导员',
                                      null=True, blank=True)
    sex = models.CharField(
        max_length=1, choices=SEX_CHOICES,
        verbose_name='性别', default='1'
    )
    student_class = models.ForeignKey(StudentClass, models.DO_NOTHING, db_column='student_class',
                                      related_name='student_class_name', default=None, verbose_name='班级', null=True,
                                      blank=True)
    id_card = models.CharField(db_column='id_card', max_length=18, null=True, blank=True, verbose_name='身份证号')
    bank_card = models.CharField(db_column='bank_card', max_length=16, null=True, blank=True, verbose_name='银行卡号')

    class Meta:
        db_table = 'userinfo'
        verbose_name_plural = '用户信息'
